﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;


namespace _3D_Game2
{
    class Kobala : BasicModel
    {
       Matrix rotation = Matrix.Identity;
       Matrix Scale = Matrix.Identity;
        Vector3 direction;
        Vector3 mydirection;
        public Vector3 myposition;
        float angle = 1;
        float speed = 2.5f;

        public Kobala(Model m, Vector3 Position, Vector3 Direction)
            : base(m)
        {
            world*= Matrix.CreateTranslation(Position);
            direction = Direction;
            direction.Normalize();
            myposition = Position;
            Scale*= Matrix.CreateScale(0.2f);
           // world *= Matrix.CreateRotationY(MathHelper.Pi);
        }

        public Vector3 GetKobalaDirection
        {
            get { return direction; }
        }
        public override void Update()
        {
            
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                //if (myposition.X <= 1100)
                //myposition.X -= speed;
                ////angle += 0.001f;
                mydirection = Vector3.Left*speed;
                world *= Matrix.CreateTranslation(mydirection);
         
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                //if(myposition.X>=-1100)
                //myposition.X += speed;
                //angle -= 0.001f;
                mydirection = Vector3.Right * speed;
                world *= Matrix.CreateTranslation(mydirection);
        

            }
            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                //if (myposition.Y <= 600)
                //myposition.Y += speed;
                mydirection = Vector3.Up * speed;
                world *= Matrix.CreateTranslation(mydirection);
   

            }
            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                //if (myposition.Y >= -600)
                //myposition.Y -= speed;
                mydirection = Vector3.Down * speed;
                world *= Matrix.CreateTranslation(mydirection);
                

            }
            if (Keyboard.GetState().IsKeyDown(Keys.Z))
            {
                    myposition.Z -= speed;

            }

            if (Keyboard.GetState().IsKeyDown(Keys.R))
            {
               angle += 0.02f;
               world *= Matrix.CreateRotationY(MathHelper.PiOver4/6);

            }
            //angle += 0.02f;
            //world =Scale * Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(myposition);
            //world = Scale * Matrix.CreateTranslation(myposition);
            //world *= Matrix.CreateRotationY(MathHelper.Pi / 1.02f);
           // world *= Matrix.CreateTranslation(Vector3.Backward);
            //world = Scale *Matrix.CreateTranslation(mydirection);
           // world *= Matrix.CreateRotationY(MathHelper.PiOver4 / 60);
            //Scale *= Matrix.CreateScale(0.3f);
        }

        public override Matrix GetWorld()
        {
            return Scale *rotation * world;
        }

    }
}
